#include "comm.hpp"

int main()
{
    //1首先创建管道文件
    int s = mkfifo(IPCPATH.c_str(),MODE);
    if(s == -1)
    {
        perror("mkfifo");
        exit(1);
    }
    int fd = open(IPCPATH.c_str(),O_RDONLY);//只读方式打开文件
    char buffer[SIZE];
    while(1)
    {
        memset(buffer,0,sizeof(buffer));
        int ret = read(fd,buffer,sizeof(buffer) - 1);
        if(ret>0)//正常读取
        {
            cout<<"writer say: "<<buffer<<endl;
        }
        else if(ret == 0)//读到了文件结尾
        {
            cout<<"writer quit,i will quit"<<endl;
            break;
        }
        else//读取失败了
        {
            perror("read");
            exit(2);
        }
    }

    close(fd);
    unlink(IPCPATH.c_str());
    return 0;
}